<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<include file="Public:base" />

<script type="text/javascript">
$(document).ready(function() {
	

    $("#roomimgupolad").change(function(e){
        var file = e.target.files[0];
        if (file.type.indexOf("image") == 0) {
			if (file.size >= 2*1024*1000) {
				alert('您这张"' + file.name
						+ '"图片大小过大，应小于2M');
			} else {
				//
				var fReader = new FileReader();
		        //console.log(fReader);
		       //console.log(file);
		        fReader.onload=(function(var_file){
			       return function(e){
			          var img = $('<img id="roomimg" class="" src="'+e.target.result+'" alt="'+var_file.name+'" />');
			          $('#roompreview').html(img);
			       }
			    })(file);
		        fReader.readAsDataURL(file);
			}
		} else {
			alert('文件"' + file.name + '"不是图片。');
		}
        
    });
	
	
	
$("#submit").on("click", function () {
		
				
				var formData = new FormData( $('#artedit')[0]);
				$.ajax({
			        url: '__URL__/setsmall',
			        type: 'POST',
			        data: formData,
			        async: false,
			        cache: false,
			        contentType: false,
			        processData: false,
			        success: function (result) {
			        	if(result=="ok"){
							bootbox.alert("设置成功", function() {
								location.href = "__URL__/getlist/id/{$art.id}";
			             	});
			       		}else {
			       			bootbox.alert("设置失败", function() {
			             	});
			       		}
			        },
			        error: function(){
			        	bootbox.alert("设置失败", function() {
		             	});
			        },	
			    });
		
	});
	
});

</script>

</head>
<body>
<include file="Public:header" />


<div class="home-index">
  <div class="container">
    <div class="row">
      <ol class="breadcrumb">
        <li>首页</li>
        <li><a class='' href="__MODULE__/Article/index/flag/roomtype">房型管理</a></li>
        <li><a class='' href="__URL__/getlist/id/{$art.id}">{$art.title}</a></li>
        <li class="active">设置缩略图</li>
      </ol>
      <div class="comm-box">
        <form id="artedit" role="form" method="post" action="__URL__/setsmall" enctype="multipart/form-data">
		 
		 <div class="form-group" id="roomimgdiv">
		 	<label>原图</label>
		 	<div >
		       <img src="__ROOT__{$originphoto.path}" class="upload_image" />
        	</div>
         </div>
		 
		<div class="form-group" id="roomimgdiv">
		 	<label>缩略图上传</label>
		 	<div  >
			 	<input type="file" id="roomimgupolad" name="fileselect"  placeholder="请点击上传">
		        <div id="roompreview" class="upload_preview">
		        	<img src="__ROOT__{$small.path}" class="upload_image" />
				</div>
        	</div>
         </div>
         <input type="hidden" id="photoable" name="photoable"  value='{$art.flag}' >
         <input type="hidden" name='photoable_id' value='{$art.id}' >
         <input type="hidden" name='parent_id' value='{$originphoto.id}' >
		  <input type="hidden" name='is_small' value='1' >	
          <input type="hidden" id="id" name='id' value='{$small.id}' >	
          <button type="button" id='submit' class="btn btn-primary">提交</button>
        </form>
      </div>
    </div>
  </div>
</div>

</body>
</html>